

#import "RootViewController.h"
#import "MyLauncherItem.h"
#import "CustomBadge.h"
#import "ItemViewController.h"
#import "FMDBCollectionManager.h"
#import "Collection.h"
#import "UICustomImageView.h"
#import "MyLauncherViewController.h"


@implementation RootViewController

-(void)loadView
{    
    NSString *filePath=[[NSBundle mainBundle] pathForResource:@"searchBarBg" ofType:@"png"];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithContentsOfFile:filePath] forBarMetrics: UIBarMetricsDefault];
}



- (void)viewWillAppear:(BOOL)animated
{
[super loadView];
self.title = @"收藏";
[[self appControllers] setObject:[ItemViewController class] forKey:@"ItemViewController"];

FMDBCollectionManager *fmdbCollectionManager = [[FMDBCollectionManager alloc] init];
collectionArray = [fmdbCollectionManager getAllCollection];
//第一页数组
NSMutableArray *fArray=[[NSMutableArray alloc] initWithCapacity:9];
//第二页数组
NSMutableArray *sArray=[[NSMutableArray alloc] initWithCapacity:9];
    
    

    for(Collection *collection in collectionArray){
        if(collection.page==1){
            MyLauncherItem *temp= [[MyLauncherItem alloc] initWithTitle:collection.supplierName
                                                        iPhoneImage:collection.imgUrl 
                                                          iPadImage:@"itemImage-iPad"
                                                             target:[NSString stringWithFormat:@"%d",collection.supplierId] 
                                                        targetTitle:@"Item 11 View"
                                                          deletable:YES];
            [fArray addObject:temp];
        }
        else{
            MyLauncherItem *temp2= [[MyLauncherItem alloc] initWithTitle:collection.supplierName
                                                            iPhoneImage:collection.imgUrl 
                                                              iPadImage:@"itemImage-iPad"
                                                                 target:[NSString stringWithFormat:@"%d",collection.supplierId] 
                                                            targetTitle:@"Item 11 View"
                                                              deletable:YES];
            [sArray addObject:temp2];
        }
    }
    if([sArray count]==0){
        [self.launcherView setPages:[NSMutableArray arrayWithObjects: fArray,nil]];
    }
    else{
        [self.launcherView setPages:[NSMutableArray arrayWithObjects: fArray,sArray,nil]];
    }
}

- (void)didReceiveMemoryWarning 
{
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload 
{
    NSLog(@"rootviewcontroller");
    [super viewDidUnload];
}

@end
